import Vue from "vue";
import VueRouter from "vue-router";
import Nav from "@/views/Nav.vue";

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Nav",
    component: Nav,
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "Home",
        component: () => import("@/views/Home"),
      },
      {
        path: "/favorite",
        name: "Favorite",
        component: () => import("@/views/Favorite"),
      },
      {
        path: "/add",
        name: "Add",
        component: () => import("@/views/Add"),
      },
      {
        path: "/register",
        name: "Register",
        component: () => import("@/views/Register"),
      },
      {
        path: "/chat",
        name: "Chat",
        component: () => import("@/views/Chat"),
      },
      {
        path: "/account",
        name: "Account",
        component: () => import("@/views/Account"),
      },
      {
        path: "/result",
        name: "SearchResult",
        component: () => import("@/views/SearchResult"),
      },
    ],
  },
  {
    path: "/meal",
    name: "Meal",
    component: () => import("@/views/Meal.vue"),
  },
  {
    path: "/buy/:id",
    name: "Buy",
    component: () => import("@/views/Buy.vue"),
  },
  {
    path: "/pay/:id",
    name: "Pay",
    component: () => import("@/views/Pay.vue"),
  },
  {
    path: "/send",
    name: "Send",
    component: () => import("@/views/Send.vue"),
  },
  {
    path: "/info",
    name: "Info",
    component: () => import("@/views/Info.vue"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/Login.vue"),
  },
  {
    path: "/search",
    name: "Search",
    component: () => import("@/views/Search"),
  },
 
  {
    path: "/detail",
    name: "Detail",
    component: () => import("@/views/Detail"),
  },
  {
    path: "/edit",
    name: "Edit",
    component: () => import("@/views/Edit.vue"),
  },
  {
    path: "/profile",
    name: "Profile",
    component: () => import("@/views/Profile.vue"),
  },
  {
    path: "/chatDetail",
    name: "ChatDetail",
    component: () => import("@/views/ChatDetail.vue"),
  },
  {
    path: "/consume",
    name: "ConsumeList",
    component: () => import("@/views/ConsumeList.vue"),
  },
  {
    path: "/charge",
    name: "Charge",
    component: () => import("@/views/Charge.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
